package chpt07;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Callable_Fib {

	public static void main(String[] args) throws InterruptedException {
		ExecutorService exec = Executors.newCachedThreadPool();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();// num of tasks
		List<CalculateTask> taskList = new ArrayList<CalculateTask>();
		List<Future<Integer>> results = new ArrayList<Future<Integer>>();
		int sum = 0;

		for (int i = 0; i < n; i++) {
			taskList.add(new CalculateTask(i));
		}
		for (int i = 0; i < n; i++) {
			results.add(exec.submit(taskList.get(i)));
		}
		/*try{
			results = exec.invokeAll(taskList);
		} catch (InterruptedException e) {
		    e.printStackTrace();
		}*/
		for (Future<Integer> fs : results) {
			try {
				sum += fs.get();
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (ExecutionException e) {
				e.printStackTrace();
			} finally {
				exec.shutdown();
			}
		}
		System.out.println("sum=" + sum);
		sc.close();
	}
}

class CalculateTask implements Callable<Integer> {
	private int n;

	public CalculateTask(int n) {
		this.n = n;
	}

	public CalculateTask() {
		super();
	}

	@Override
	public Integer call() throws Exception {
		int a = 1;
		int b = 1;
		for (int j = 1; j < n; j++) {
			int temp = a + b;
			a = b;
			b = temp;
		}
		return b;
	}

}
